Using the "Outline" object

The "Outline" object, as it was already said, represents a report’s tree, which can be displayed in a preview window. Clicking on a tree’s element executes jumping to the report’s page, which is connected to the tree’s element. It is not necessary to use the script for operating with the "Outline," since some bands have a mechanism, which enables to automatically form a tree. Let us examine two examples of how the "Outline" can be used with the help of bands and the script.

Almost all bands have the "OutlineText" property, into which a line-expression can be put, and this in turn helps to automatically create a tree. The expression will be calculated when forming a report, and its value will be added to the tree when printing the band. Thus, elements’ hierarchy in the tree is similar to the bands’ hierarchy in a report. That means, that in the tree there will be main and subordinate elements, corresponding to main and subordinate bands in a report (a report with two levels of data or with groups can exemplify the point). Let us illustrate process of operating with a tree by the example of the report with groups, which we examined in the previous chapter.

Specify a value for the "GroupHeader1.OutlineText" band’s property as "<Group."Company">." To make the tree be displayed automatically as soon as the preview window opens, one should set the "Report.PreviewOptions.OutlineVisible = True" property. When starting the report, you would see the following:

Clicking on any element of the tree executes jumping to the corresponding report’s page, and, as a result, the selected element occurs on the top of the window.

Let us add the second level to the report’s tree. To perform this, it is enough to set the "MasterData.OutlineText" band’s property as "<Group."OrderNo">." Thus, the tree will look as follows:

As you might notice, the navigation even in the orders’ numbers is possible, and hierarchy of the tree’s elements resembles the report’s hierarchy.

Now let us show, how to form/compose an analogous tree via the script without using the "OutlineText" property. In our report, clear the "OutlineText" properties of both bands and create two event’s handlers: "GroupHeader1.OnBeforePrint" and "MasterData1.OnBeforePrint":

procedure GroupHeader1OnBeforePrint(Sender: TfrxComponent);

begin

Outline.LevelRoot;

Outline.AddItem(<Group."Company">);

end;

procedure

MasterData1OnBeforePrint(Sender: TfrxComponent);

begin

Outline.AddItem(<Group."OrderNo">);

Outline.LevelUp;

end;

begin

end.

When starting a report, make sure, that it works in the same way as the previous report, where the tree was formed automatically. Let us examine, how a tree is formed.

The "Outline.AddItem" method adds a child block to the current tree block, and then makes the child block a current one. Thus, if "AddItem" were called several times in a row, we would receive a "ladder" as shown below:

Item1
  Item2
    Item3
     ...

The "LevelUp" and "LevelRoot" Outline methods are used for controlling the current element. The first one moves the cursor to the element, which is located on a higher level. Thus, the script

Outline.AddItem('Item1');

Outline.AddItem('Item2');

Outline.AddItem('Item3');

Outline.LevelUp;

Outline.AddItem('Item4');

constructs a tree like this

Item1
  Item2
    Item3
    Item4

That means, that "Item4" will be a child element in relation to the "Item2" element. The "LevelRoot" method shifts the current element to the root of the tree. For example, the script

Outline.AddItem('Item1');

Outline.AddItem('Item2');

Outline.AddItem('Item3');

Outline.LevelRoot;

Outline.AddItem('Item4');

constructs a tree, like the one below

Item1
  Item2
    Item3
Item4

Thanks to these explanations, it becomes clear, how our report works. Every time when printing a group title, the root of the tree becomes the current element, where a company’s name is added. After that, the list of orders is typed, and each order is added as a child element of the company. To make the numbers of orders located on one level, and not displayed as a "ladder", the transition to the upper level via the "Outline.LevelUp" method is performed in the script.